package com.markerhub.controller;


import com.markerhub.common.lang.Result;
import com.markerhub.entity.User;
import com.markerhub.service.UserService;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.lang.reflect.Array;
import java.util.ArrayList;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lisipeng
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    UserService userService;

//    @RequiresAuthentication
    @PostMapping("/index")
    public Result index() {
        User user = userService.getById(1L);
        return Result.succ(user);
    }

    @PostMapping("/save")
    public Result save(@Validated @RequestBody User user) {
        return Result.succ(user);
    }

    /**
     * 获取读者概况（访问设备信息统计）
     * */
    @PostMapping("/readerinfo")
    public Result readerinfo(){
        String str = "[" +
                "{ value: 121, name: 'Windows' }," +
                "{ value: 55, name: 'Android' }," +
                "{ value: 12, name: 'IOS' }," +
                "{ value: 0, name: 'Linux' }," +
                "{ value: 1, name: '其他' }" +
                "]";
        return Result.succ(str);
    }

}
